package com.fenghongzhang.login.mvp.view;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.fenghongzhang.lib.mvp.view.BaseFragment;
import com.fenghongzhang.login.LoginAndRegisterActivity;
import com.fenghongzhang.login.MainActivity;
import com.fenghongzhang.login.R;
import com.fenghongzhang.login.entity.LoginInfo;
import com.fenghongzhang.login.mvp.contract.LoginContract;
import com.fenghongzhang.login.mvp.model.LoginModel;
import com.fenghongzhang.login.mvp.presenter.LoginPresenter;

/**
 * A simple {@link Fragment} subclass.
 */
public class LoginFragment extends BaseFragment<LoginPresenter> implements LoginContract.ILoginView {

    private MyListener myListener ;
    //内部接口,页面回调
    public interface MyListener {
        void click(int i);
    }


    private EditText fgName;
    private EditText fgPwd;
    private Button fgRegister;

    private Button fgLogin;
    @Override
    public int bindLayout() {
        return R.layout.fragment_login;
    }

    @Override
    public void initView() {

        fgName = (EditText) findViewById(R.id.fg_name);
        fgPwd = (EditText) findViewById(R.id.fg_pwd);
        fgRegister = (Button) findViewById(R.id.fgRegister);
        fgLogin = (Button) findViewById(R.id.fgLogin);

        //Activity页面监听
        myListener = (MyListener) getActivity();

        //登录点击事件
        fgLogin.setOnClickListener(v -> {
            mPresenter.login();
        });

        //注册点击事件
        fgRegister.setOnClickListener(v ->{
            myListener.click(1);
        } );
    }



    @Override
    public void initData() {
        //和页面中一样
        mPresenter = new LoginPresenter(new LoginModel(),this);
    }

    @Override
    public String getName() {
        return fgName.getText().toString();
    }

    @Override
    public String getPwd() {
        return fgPwd.getText().toString();
    }

    @Override
    public void isLoginOk(LoginInfo info) {
        //此方面在baseFragment中已经重新过.
        showMsg(info.getMessage());
    }


    @Override
    public void showLoading() {
        //暂时不需要
    }

    @Override
    public void hideLoading() {

    }
}
